home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / INCLUDE / ABOUT.C next >
Text File  |  1994-12-26  |  5KB  |  126 lines

  1. BOOL CenterWindow (HWND hwndChild, HWND hwndParent)
  2. {
  3.    RECT    rChild, rParent;
  4.    int     wChild, hChild, wParent, hParent;
  5.    int     wScreen, hScreen, xNew, yNew;
  6.    HDC     hdc;
  7.  
  8.    // Get the Height and Width of the child window
  9.    GetWindowRect (hwndChild, &rChild);
  10.    wChild = rChild.right - rChild.left;
  11.    hChild = rChild.bottom - rChild.top;
  12.  
  13.    // Get the Height and Width of the parent window
  14.    GetWindowRect (hwndParent, &rParent);
  15.    wParent = rParent.right - rParent.left;
  16.    hParent = rParent.bottom - rParent.top;
  17.  
  18.    // Get the display limits
  19.    hdc = GetDC (hwndChild);
  20.    wScreen = GetDeviceCaps (hdc, HORZRES);
  21.    hScreen = GetDeviceCaps (hdc, VERTRES);
  22.    ReleaseDC (hwndChild, hdc);
  23.  
  24.    // Calculate new X position, then adjust for screen
  25.    xNew = rParent.left + ((wParent - wChild) /2);
  26.    if (xNew < 0) 
  27.       xNew = 0;
  28.    else if ((xNew+wChild) > wScreen) 
  29.       xNew = wScreen - wChild;
  30.  
  31.    // Calculate new Y position, then adjust for screen
  32.    yNew = rParent.top  + ((hParent - hChild) /2);
  33.    if (yNew < 0) 
  34.       yNew = 0;
  35.    else if ((yNew+hChild) > hScreen) 
  36.       yNew = hScreen - hChild;
  37.  
  38.    // Set it, and return
  39.    return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  40. }
  41.  
  42.  
  43. LRESULT CALLBACK About( HWND hDlg,           // window handle of the dialog box
  44.                         UINT message,        // type of message
  45.                         WPARAM wParam,       // message-specific information
  46.                         LPARAM lParam)
  47. {
  48.    static  HFONT hfontDlg;
  49.  
  50.    switch (message) 
  51.    {
  52.        case WM_INITDIALOG:  // message: initialize dialog box
  53.                {
  54.                   LPSTR   lpVersion;       
  55.                   DWORD   dwVerInfoSize;
  56.                   DWORD   dwVerHnd;
  57.                   UINT    uVersionLen;
  58.                   WORD    wRootLen;
  59.                   BOOL    bRetCode;
  60.                   int     i;
  61.                   char    szFullPath[256];
  62.                   char    szResult[256];
  63.                   char    szGetName[256];
  64.  
  65.                   // Create a font to use
  66.                   hfontDlg = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  67.                                         VARIABLE_PITCH | FF_SWISS, "");
  68.  
  69.                   CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  70.  
  71.                   // Get version information from the application
  72.                   GetModuleFileName (hInst, szFullPath, sizeof(szFullPath));
  73.                   dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  74.                   if (dwVerInfoSize) 
  75.                   {
  76.                        // If we were able to get the information, process it:
  77.                        LPSTR   lpstrVffInfo;
  78.                        HANDLE  hMem;
  79.                        hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  80.                        lpstrVffInfo  = GlobalLock(hMem);
  81.                        GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo);
  82.                        lstrcpy(szGetName, "\\StringFileInfo\\040904B0\\");
  83.                        wRootLen = lstrlen(szGetName);
  84.  
  85.                        // Walk through the dialog items that we want to replace:
  86.                        for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) 
  87.                        {
  88.                            GetDlgItemText(hDlg, i, szResult, sizeof(szResult));
  89.                            szGetName[wRootLen] = (char)0;
  90.                            lstrcat (szGetName, szResult);
  91.                            uVersionLen   = 0;
  92.                            lpVersion     = NULL;
  93.                            bRetCode      =  VerQueryValue((LPVOID)lpstrVffInfo,
  94.                                                           (LPSTR)szGetName,
  95.                                                           (LPVOID)&lpVersion,
  96.                                                           (LPDWORD)&uVersionLen); 
  97.  
  98.                            if ( bRetCode && uVersionLen && lpVersion) 
  99.                            {
  100.                                  // Replace dialog item text with version info
  101.                                  lstrcpy(szResult, lpVersion);
  102.                                  SetDlgItemText(hDlg, i, szResult);
  103.                                  SendMessage (GetDlgItem (hDlg, i), WM_SETFONT, (UINT)hfontDlg, TRUE);
  104.                            }
  105.                        } // for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++)
  106.  
  107.                        GlobalUnlock(hMem);
  108.                        GlobalFree(hMem);
  109.                   } // if (dwVerInfoSize)
  110.                }
  111.                return (TRUE);
  112.  
  113.        case WM_COMMAND:                              // message: received a command
  114.                if (   LOWORD(wParam) == IDOK         // "OK" box selected?
  115.                    || LOWORD(wParam) == IDCANCEL)    // System menu close command?
  116.                {
  117.                        EndDialog(hDlg, TRUE);        // Exit the dialog
  118.                        DeleteObject (hfontDlg);
  119.                        return (TRUE);
  120.                }
  121.                break;
  122.    }
  123.  
  124.    return (FALSE); 
  125. }
  126.